package com.sgb.kjwl.view.ui.adapter.enterprise;

import android.content.Context;
import android.view.View;

import androidx.recyclerview.widget.LinearLayoutManager;

import com.sgb.kjwl.BR;
import com.sgb.kjwl.R;
import com.sgb.kjwl.databinding.ItemServiceprojectclassBinding;
import com.sgb.kjwl.model.entity.enterprise.ServiceProjectClassEntity;
import com.swgk.core.recyclerview.adapter.BaseRecycleAdapter;
import com.swgk.core.recyclerview.adapter.ItemViewHolder;

import java.util.List;

public class ServiceProjectClassListAdpater extends BaseRecycleAdapter<ServiceProjectClassEntity> {

    private ClickLister lister;


    public ServiceProjectClassListAdpater(Context context, List<ServiceProjectClassEntity> datas) {
        super(context, R.layout.item_serviceprojectclass, datas);
    }

    @Override
    public void convert(ItemViewHolder holder, ServiceProjectClassEntity serviceProjectClassEntity) {
        holder.setBinding(BR.mModel, serviceProjectClassEntity);
        if (holder.getmBinding() instanceof ItemServiceprojectclassBinding && lister != null) {

            ((ItemServiceprojectclassBinding) holder.getmBinding()).llAdd.setOnClickListener(view -> lister.onclick(view, holder.getIndex_position(), 0));
            ((ItemServiceprojectclassBinding) holder.getmBinding()).imageDelete.setOnClickListener(view -> lister.onclick(view, holder.getIndex_position(), 0));
            ((ItemServiceprojectclassBinding) holder.getmBinding()).imageUpdate.setOnClickListener(view -> lister.onclick(view, holder.getIndex_position(), 0));
            ((ItemServiceprojectclassBinding) holder.getmBinding()).recycler.setLayoutManager(new LinearLayoutManager(context));
            ((ItemServiceprojectclassBinding) holder.getmBinding()).recycler.setAdapter(new ServiceProjectClassListLabelAdpater(context, serviceProjectClassEntity.getChild(), holder.getIndex_position(), lister));


        }
    }


    public void setLister(ClickLister lister) {
        this.lister = lister;
    }

    public interface ClickLister {
        /**
         * @param view      点击的view
         * @param options_1 下标1
         * @param options_2 下标2
         */
        public void onclick(View view, int options_1, int options_2);
    }
}
